package com.hualan.service;

import com.hualan.domain.Fm1;
import com.hualan.mapper.FmMapper1;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FMService1 {
    @Autowired
    public FmMapper1 fmMapper;
    public R selectAll(){
        List<Fm1> list = fmMapper.selectAll();
        if (list==null){
            return R.fail(500);
        }else {
            return R.success(list);
        }
    }

    public R update(Long id, String name, String music, String picture) {
        int i = fmMapper.updateByPrimaryKey(new Fm1(id, name, music, picture));
        if (i==0){
            return R.fail(500);
        }else {
            return R.success(i);
        }

    }

    public R delete(Long id) {
        int i = fmMapper.deleteByPrimaryKey(id);
        if (i==0){
            return R.fail(500);
        }else {
            return R.success(i);
        }
    }

    public R insert(String name, String music, String picture) {
        int i = fmMapper.insert(new Fm1(name, music, picture));
        if (i==0){
            return R.fail(500);
        }else {
            return R.success(i);
        }
    }

    public R selectAllByPage(Integer page, Integer size) {
        List<Fm1> fms = fmMapper.selectAllByPage(page, size);
        if (fms==null){
            return R.fail(500);
        }else {
            return R.success(fms);
        }
    }

    public R totalPage() {
        int i = fmMapper.totalPage();
        if (i==0){
            return R.fail(500);
        }else {
            return R.success(i);
        }
    }


    public R selectLikeName(String name) {
        List<Fm1> fms = fmMapper.selecLikeName(name);
        if (fms==null){
            return R.fail(500);
        }else {
            return R.success(fms);
        }
        }

}
